﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace psafth.RCTiming.Main.Controls
{
    /// <summary>
    /// Interaction logic for EventDisplayControl.xaml
    /// </summary>
    public partial class EventDisplayControl : UserControl
    {
        private Event _raceEvent;
        private MainWindow _mainWindow;

        public EventDisplayControl(Event ev, MainWindow mw)
        {
            InitializeComponent();

            _mainWindow = mw;

            _raceEvent = ev;

            lblDateDuration.Text = string.Format("{0} - {1}", _raceEvent.StartDate.ToString("yyyy.MM.dd"), _raceEvent.EndDate.ToString("yyyy.MM.dd"));
            lblHeader.Text = _raceEvent.EventName;
            lblOrganizer.Text = _raceEvent.Organizer;

            var t = _raceEvent.Participants.GroupBy(r => r.RaceClassId);
            RaceClassList.ItemsSource = _raceEvent.Participants.GroupBy(r => r.RaceClassId);

            if (ev.Heats != null && ev.Heats.Count > 0)
            {
                btnCreateHeats.IsEnabled = false;
            }
            else
            {
                btnRunHeat.IsEnabled = false;
            }
        }

        private void btnCreateHeats_Click(object sender, RoutedEventArgs e)
        {
            psafth.RCTiming.Main.Pages.Dialogs.MakeRacesDialog prd = new psafth.RCTiming.Main.Pages.Dialogs.MakeRacesDialog(_raceEvent, _mainWindow);
            prd.Owner = _mainWindow;
            prd.ShowDialog();

            //EventHelper.CreateRacingHeats(_raceEvent);
        }

        private void btnRunHeat_Click(object sender, RoutedEventArgs e)
        {
            psafth.RCTiming.Main.Pages.Dialogs.SelectHeatDialog prd = new Pages.Dialogs.SelectHeatDialog(_raceEvent, _mainWindow);
            prd.Owner = _mainWindow;
            prd.ShowDialog();
            //_mainWindow.MainFrame.Navigate(new Pages.RacePage(_mainWindow, _raceEvent.Heats.FirstOrDefault()));
        }

        private void btnCompetitors_Click(object sender, RoutedEventArgs e)
        {
            Reporting.PDFHelper.CreateStartList(_raceEvent);
        }
    }
}
